package org.jeecg.modules.oa.mapper;

import java.util.Date;
import java.util.List;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.jeecg.modules.oa.entity.OaReportWeek;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springframework.stereotype.Repository;

/**
 * @Description: 周报表
 * @Author: jeecg-boot
 * @Date: 2019-09-17
 * @Version: V1.0
 */
@Repository
public interface OaReportWeekMapper extends BaseMapper<OaReportWeek> {

    List<OaReportWeek> findSelfList(@Param("page") Page<OaReportWeek> page, @Param("reportWeek") OaReportWeek reportWeek);

    OaReportWeek findByUserNo(@Param("reportWeek") OaReportWeek reportWeek);

    List<OaReportWeek> findAllList(@Param("page") Page<OaReportWeek> page, @Param("reportWeek") OaReportWeek reportWeek,@Param("departIds") String departIds);

    List<OaReportWeek> findAllListToOutSource(@Param("reportWeek") OaReportWeek reportWeek);

    @Select("select * from oa_report_week where create_by = #{id} and work_date_from <= #{date} and work_date_to >= #{date}  and del_flag = '0'")
    OaReportWeek findByCreateBYAndNew(@Param("id") String id, @Param("date") Date date);

    @Select("SELECT a.id,'点击查看详情' as workContent,a.work_date_from,a.work_date_to" +
            ",(SELECT count(s.id) FROM oa_comment s WHERE s.topic_id = a.id and s.create_by != #{userId} " +
            " AND s.update_time >= IFNULL (( SELECT update_time  FROM oa_comment_record where topic_id = s.topic_id and user_id = #{userId} ) , '2017-12-06 10:49:59' )  ) AS comment_count " +
            " FROM oa_report_week a WHERE a.create_by = #{userId} AND (DATE_FORMAT(a.work_date_from,'%Y-%m') = #{date} OR DATE_FORMAT(a.work_date_to,'%Y-%m') = #{date}) ORDER BY a.create_time ASC ")
    List<OaReportWeek> appFindReportWeekList(@Param("date") String date,@Param("userId") String userId);
}
